{extend name="public/base"}

{block name="title"}
我的爱车
{/block}

{block name="style"}
{css href="/static/wechat/css/center.css" /}
<style>
    .myCar .msui_list-items input {
        width:100%;
    }
</style>
{/block}

{block name="body"}
<div class="pageControl myCar">
    <div class="msui_nav msui_navTop">
        <a class="msui_navTop-back" href="javascript:history.back();"><i class="micon-back"></i></a>
        <h1 class="msui_navTop-title">我的爱车</h1>
        <a href="javascript:;" class="msui_navTop-login save_my_car">保存</a>
    </div>
    <div class="weui-top">
        <form id="my_car">
            <div class="msui_table msui_tableCom">
                <div class="msui_tabCell-img">
                    <div class="weui-uploader__input-box image" {notempty name='my_car.image'}style="background:url({$my_car.image}) no-repeat"{/notempty}>
                    <input id="uploaderInput" class="weui-uploader__input one_upload" type="file" accept="image/*"  file-attr="" />
                    <input type="hidden" name="image" value="" />
                </div>
            </div>
            <div class="msui_tabCell-content">
                <p class="fs085 cl-3333">{$brand.brand_name} {$model.name}</p>
                <input type="hidden" name="name" value="{$brand.brand_name} {$model.name}" />
                <p style="margin-top: 5px; font-size: .7rem; color: #666;">
                    <input type="text" name="mileage"  class="fs075 cl-9999" placeholder="点击设置" value="{$my_car.mileage|default=''}" style="border: none; width: 3.5rem;">Km
                    <br />行驶里程
                </p>
            </div>
            <!--<div class="msui_tabCell-button">-->
            <!--<a href="editCarMsg.html" class="cl-orange fs07 bc-orange">更换</a>-->
            <!--<a class="cl-orange fs07 bc-orange mt10">编辑里程</a>-->
            <!--</div>-->
    </div>
    <div class="weui-cells">
        <div class="msui_cells-title fs08 cl-6666">基本信息</div>
        <div class="msui_list">
            <div class="msui_list-items">
                <a class="msui_table msui_tableCom">
                    <div class="msui_tabCell-content">
                        <p class="fs085 cl-3333">请设置排量</p>
                        <!--<input id="carConsume" class="fs075 cl-9999" placeholder="排量">-->
                        <input type="text" name="displacement"  class="fs075 cl-9999" placeholder="排量" value="{$my_car.displacement|default=''}">
                    </div>
                    <div class="msui_tabCell-button">
                        <i class="micon-in bc-9999"></i>
                    </div>
                </a>
            </div>
            <div class="msui_list-items">
                <a class="msui_table msui_tableCom">
                    <div class="msui_tabCell-content">
                        <p class="fs085 cl-3333">请选择生产年份</p>
                        <!--<input id="carYear" class="fs075 cl-9999" placeholder="成产年份">-->
                        {gt name="my_car.start_off_time|default=0" value="0"}
                        <input type="date" name="production_time" class="fs075 cl-9999" placeholder="上路时间" value="{$my_car.production_time|date='Y-m-d', ###}">
                        {else /}
                        <input type="date" name="production_time" class="fs075 cl-9999" placeholder="上路时间" value="">
                        {/gt}
                    </div>
                    <div class="msui_tabCell-button">
                        <i class="micon-in bc-9999"></i>
                    </div>
                </a>
            </div>
            <div class="msui_list-items">
                <a class="msui_table msui_tableCom">
                    <div class="msui_tabCell-content">
                        <p class="fs085 cl-3333">请选择上路时间</p>
                        <!--<input id="firstTime" class="fs075 cl-9999" placeholder="上路时间">-->
                        {gt name="my_car.start_off_time|default=0" value="0"}
                        <input type="date" name="start_off_time" class="fs075 cl-9999" placeholder="上路时间" value="{$my_car.start_off_time|date='Y-m-d', ###}">
                        {else /}
                        <input type="date" name="start_off_time" class="fs075 cl-9999" placeholder="上路时间" value="">
                        {/gt}
                    </div>
                    <div class="msui_tabCell-button">
                        <i class="micon-in bc-9999"></i>
                    </div>
                </a>
            </div>
        </div>
    </div>
    <div class="weui-cells">
        <div class="msui_cells-title fs08 cl-6666">详细信息</div>
        <div class="msui_list">
            <div class="msui_list-items" style="width: 30%">
                <a class="msui_table msui_tableCom">
                    <div class="msui_tabCell-content">
                        <p class="fs085 cl-3333">归属地</p>
                        <input type="text" name="location"  class="fs075 cl-9999" placeholder="归属地" value="{$my_car.location|default=''}">
                    </div>
                    <div class="msui_tabCell-button">
                        <i class="micon-in bc-9999"></i>
                    </div>
                </a>
            </div>
            <div class="msui_list-items" style="width:70%;">
                <a class="msui_table msui_tableCom">
                    <div class="msui_tabCell-content">
                        <p class="fs085 cl-3333">请填写车牌号</p>
                        <input type="text" name="plate" class="fs075 cl-9999" placeholder="车牌号" value="{$my_car.plate|default=''}">
                    </div>
                    <div class="msui_tabCell-button">
                        <i class="micon-in bc-9999"></i>
                    </div>
                </a>
            </div>
        </div>
    </div>
    <input type="hidden" name="brand_id" value="{$brand.id}">
    <input type="hidden" name="model_id" value="{$model.id}">
    <input type="hidden" name="id" value="{$my_car.id|default=0}">
    </form>
    </div>

</div>
<!-- loading toast -->
<div id="loadingToast" style="display:none;">
    <div class="weui-mask_transparent"></div>
    <div class="weui-toast" style="opacity: 1; visibility: visible;">
        <i class="weui-loading weui-icon_toast"></i>
        <p class="weui-toast__content">加载中...</p>
    </div>
</div>
{/block}
{block name="javascript"}
<script>
    $(function () {
        $("#uploaderInput").change(function(){
            $('#loadingToast').fadeIn();
            window.setTimeout(function(){
                var formData = new FormData();
                formData.append("type","car");
                formData.append("img",$("#uploaderInput")[0].files[0]);
                $.ajax({
                    url: '{:url("Base/get_upload_img")}' ,
                    type: 'POST',
                    data: formData,
                    async: false,
                    cache: true,
                    contentType: false,
                    processData: false,
                    dataType:"json",
                    success: function (d) {
                        if(!d.code){
                            var code = d.code;
                            $.alert(error_code[code]);
                        }else{
                            $("input[name='image']").val(d.data.path);
                            $(".image").css('background', 'url('+d.data.path+') no-repeat');
    //                        $(".weui-uploader__input-box:after, .weui-uploader__input-box:before").css('z-index', -1);
                        }
                        $('#loadingToast').fadeOut();
                    },
                    error: function (d) {
                        alert('网络异常');$('#loadingToast').fadeOut();
                    }
                });
            },666);

        });

        // 提交
        $(".save_my_car").click(function () {
            $('#loadingToast').fadeIn();
            var _obj = $("#my_car");
            $.ajax({
                type : 'POST',
                url : '?',
                data : _obj.serialize(),
                dataType : 'json',
                success : function (msg) {
                    if (msg.code == 200) {
                        alert('保存成功！！');
                        window.location.href = "{:url('w_member_role_info/save_role_info', ['type' => 0])}";
                    } else {
                        var code = msg.code;
                        $.alert(error_code[code]);
                    }
                }
            });
        });
    });
</script>
{/block}
